﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using DevExpress.Web.ASPxMenu;
using SGRapidForm.Common;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Permission.Entity;
using DevExpress.Web.ASPxEditors;


namespace SGDemo.Permission
{
    public partial class AssociatedModules : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
            Bind();
        }

        protected void Bind()
        {
            if (this.Request.QueryString["Keyid"] == null)
            {
                throw new ArgumentException("查询字符串‘Keyid’不能为空");
            }
            List<PermissionDetails> PerDetailsCollection = _permissionService.RoleModule_GetDetailsByRoleKeyid(this.Request.QueryString["Keyid"]);

            ListEditItem lei;
            foreach (PermissionDetails item in PerDetailsCollection)
            {
                lei = new ListEditItem(item.Name, item.Keyid);
                lei.Selected = item.IsSelected;
                cblModuleList.Items.Add(lei);
            }
        }

        [AjaxPro.AjaxMethod]
        public bool SaveModules(string roleKeyid, string[] moduleKeyids)
        {
            return _permissionService.RoleModule_BulkAdd(roleKeyid, moduleKeyids);
        }
    }
}